﻿<Controls:SinacorWindow 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:Custom="http://schemas.xceed.com/wpf/xaml/datagrid"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	xmlns:Controls="clr-namespace:Sinacor.Infra.UI.Controls.SmartClient;assembly=Sinacor.Infra.UI.Controls"
	WindowStartupLocation="CenterScreen"
    WindowState="Maximized"
	Title="{DynamicResource FaturamentoBovespa.Cadastros.Label.CadastroCarteiraMercado}"	
	x:Class="Sinacor.UI.Bovespa.Parametro.View.SmartClient.CadastroCarteiraMercado"
    ModulePlus="False"
    ModuleId="ORD">


    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Controls:SinacorExpanderContainer Width="Auto" Height="Auto">
            <Controls:SinacorExpanderContainer.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Controls:SinacorExpanderContainer.RowDefinitions>
            <Controls:SinacorExpander Grid.Row="0"
									  HorizontalAlignment="Stretch"
									  VerticalAlignment="Stretch"
									  Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.Pesquisa}"
									  IsExpanded="True" 
									  Height="Auto">
                <Grid>
                    <Controls:SinacorGroupBox HorizontalAlignment="Left" 
                		                        VerticalAlignment="Top" 
                		                        Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.Natureza}" 
						                        Height="55" 
						                        Width="226">
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                            <Controls:SinacorRadioButton x:Name="rdbCompra"
                                                         Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.Compra}" 
                                                         Margin="0,0,0,0" 
                                                         HorizontalAlignment="Left" 
                                                         VerticalAlignment="Top" 
                                                         Width="100"                                                                                                                   
                                                         TabIndex="1"
                                                         GroupName="NatOpera"
                                                         IsChecked="True" />
                            
                            <Controls:SinacorRadioButton x:Name="rdbVenda"
                                                         Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.Venda}" 
                                                         Margin="104,0,0,0" 
                                                         HorizontalAlignment="Left" 
                                                         VerticalAlignment="Top" 
                                                         Width="100" 
                                                         TabIndex="2"
                                                         GroupName="NatOpera" />
                        </Grid>
                    </Controls:SinacorGroupBox>
                    <Controls:SinacorLabel  Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.Bolsas}" 
                		                    Width="109" 
                		                    Margin="245,0,0,0" 
                                            HorizontalAlignment="Left" 
                                            HorizontalContentAlignment="Left" 
                                            IsTargetFieldRequired="True" />
                    <Controls:SinacorComboBox x:Name="cboBolsas" 
                                              ItemsSource="{Binding ListaBolsas}"
                                              SelectedValue="{Binding Path=FiltroMercado.CodigoBolsa}"                                               
                                              IsRequired="True"                                                  
                                              DisplayMemberPath="NomeResumido"
                                              SelectedValuePath="CodigoBolsa"                                              
                                              Margin="245,21,0,0" 
                                              VerticalAlignment="Top" 
                                              Width="300" 
                                              WidthPopup="400" 
                                              TabIndex="3" 
                                              HorizontalAlignment="Left"/>
                    <!-- BOTOES PESQUISA -->
                    <Controls:SinacorButton x:Name="btnPesquisa"
                                            HorizontalAlignment="Left"
                		                    Margin="565,21,0,0"
                		                    Width="100"
                		                    Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.Pesquisa}"
                		                    VerticalAlignment="Top"
                		                    IsDefault="True"
                		                    TabIndex="4"                                            
                                            OnBufferedClick="btnPesquisa_OnBufferedClick"
                                            />                    
                    <Controls:SinacorButton x:Name="btnNovaPesquisa"
                                            HorizontalAlignment="Left"
                		                    Margin="669,21,0,0"
                		                    Width="115"
                		                    Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.NovaPesquisa}"
                		                    VerticalAlignment="Top"
                		                    TabIndex="5"                                             
                                            OnBufferedClick="btnNovaPesquisa_OnBufferedClick"/>
                </Grid>
            </Controls:SinacorExpander>
            
            <Controls:SinacorExpander Grid.Row="1"
									  HorizontalAlignment="Stretch"
									  VerticalAlignment="Stretch"
									  Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.Mercados}"
									  IsExpanded="True" 
									  Margin="0,4,0,0">
                <Grid>
                    <!-- GRID MERCADOS -->
                        <Controls:SinacorDataGrid x:Name="dtgMercados"
											      HorizontalAlignment="Stretch"
											      Width="Auto" 										
											      VerticalAlignment="Stretch" 										
											      Margin="0,0,0,0"
                                                  AllowBeginInsert="True" 
                                                  AllowBeginUpdate="True" 
                                                  AllowDelete="True"    
											      TabIndex="6" 
                                                  EndingInsert="dtgMercados_EndingInsert"
                                                  EndingUpdate="dtgMercados_EndingUpdate"
                                                  Deleting="dtgMercados_Deleting"
                                                  CancelingInsert="dtgMercados_CancelingInsert"
                                                  CancelingUpdate="dtgMercados_CancelingUpdate"
                                                  BufferedSelectionChanged="dtgMercados_BufferedSelectionChanged"                                                  
                                                  ItemsSource="{Binding ListaMercados}">

                            <!-- COLUNAS dtgMercados -->
                        <Controls:SinacorDataGrid.Columns>
                            <Controls:Column Name="Codigo" 
    										 Title="FaturamentoBovespa.Cadastros.Label.Codigo"
                                             AllowInsert="True" 
                                             AllowUpdate="False" 
                                             DisplayMemberPath="Codigo"
                                             Integers="3"
                                             IsRequired="True"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             HorizontalCellAlignment="Right">
                                
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorInt16TextBox x:Name="CodigoMercado"
                                                                      Integers="3"
                                                                      IsRequired="True"
                                                                      Value="{Binding Codigo, UpdateSourceTrigger=PropertyChanged}"
                                                                      LostFocus="CodigoMercado_LostFocus"/>

                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>
                            </Controls:Column>
                            
                            <!-- SIGLA -->
                            <Controls:Column Name="Sigla" 
    										 Title="FaturamentoBovespa.Cadastros.Label.Sigla" 
                                             AllowInsert="True" 
                                             AllowUpdate="False" 
                                             DisplayMemberPath="Sigla"
                                             HorizontalCellAlignment="Center">
                                <Controls:Column.CellInsertTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorTextBox x:Name="TxtSigla"                                                                 
                                                                 IsRequired="True"
                                                                 Text="{Binding Sigla}"/>
                                    </DataTemplate>
                                 </Controls:Column.CellInsertTemplate>
                            </Controls:Column>                            
                            
                            <!-- DESCRICAO -->
                            <Controls:Column Name="DescricaoMercado" 
    										 Title="FaturamentoBovespa.Cadastros.Label.Descricao" 
                                             AllowInsert="True" 
                                             AllowUpdate="True" 
                                             DisplayMemberPath="Descricao">
                                
                                <Controls:Column.CellInsertTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorTextBox x:Name="TxtDescricaoMercado"
                                                                 IsRequired="True"
                                                                 Text="{Binding Descricao}"/>
                                    </DataTemplate>
                                </Controls:Column.CellInsertTemplate>                                
                            </Controls:Column>
                            
                            <!-- NATUREZA OPERACAO -->
                            <Controls:Column Name="NaturezaOperacao" 
    										 Title="FaturamentoBovespa.Cadastros.Label.NatOper" 
                                             AllowInsert="True" 
                                             AllowUpdate="False"                                             
                                             DisplayMemberPath="NaturezaOperacao"
                                             HorizontalCellAlignment="Center"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             IsRequired="True">
                                
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorComboBox x:Name="cboNatOper"
                                                                  ItemsSource="{Binding presenter.ListaNaturezaOperacao, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:SinacorWindow}}}"
                                                                  SelectedValue="{Binding NaturezaOperacao}"
                                                                  IsRequired="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>                                
                            </Controls:Column>
                            
                            <!-- VALOR MINIMO -->
                            <Controls:Column Name="ValorMinimo" 
    										 Title="FaturamentoBovespa.Cadastros.Label.ValorMinimo" 
                                             AllowInsert="True" 
                                             AllowUpdate="True"
                                             DisplayMemberPath="ValorMinimo"
                                             HorizontalCellAlignment="Right"
                                             Integers="13"
                                             Decimals="2"/>
                            
                            <!-- VALOR UNITARIO -->
                            <Controls:Column Name="ValorUnitario" 
    										 Title="FaturamentoBovespa.Cadastros.Label.ValorUnitario" 
                                             AllowInsert="True" 
                                             AllowUpdate="True"
                                             DisplayMemberPath="ValorUnitario"
                                             HorizontalCellAlignment="Right"
                                             Integers="13"
                                             Decimals="2"/>

                            <!-- COMBO EVENTO CONTABIL -->
                            <Controls:Column Name="EventoContabil" 
    										 Title="FaturamentoBovespa.Cadastros.Label.EventoContabil"                                              
                                             AllowInsert="True" 
                                             AllowUpdate="True"                                                                                          
                                             DisplayMemberPath="DescricaoEventoContabil"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             IsRequired="True">

                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorComboBox Name="cboEventoContabil" 
                                                      ItemsSource="{Binding presenter.ListaEventosContabeis, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:SinacorWindow}}}"  
                                                      SelectedValue="{Binding CodigoEventoContabil}"
                                                      DisplayMemberPath="Descricao"
                                                      SelectedValuePath="Codigo" 
                                                      IsRequired="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>
                            </Controls:Column>

                            <Controls:Column Name="GrupoNota" 
    										 Title="FaturamentoBovespa.Cadastros.Label.GrupoNota" 
                                             AllowInsert="True" 
                                             AllowUpdate="True"
                                             DisplayMemberPath="GrupoNota"
                                             HorizontalCellAlignment="Right"/>
                            
                            <Controls:Column Name="ClassificacaoMapa" 
    										 Title="FaturamentoBovespa.Cadastros.Label.ClassMapa" 
                                             AllowInsert="True" 
                                             AllowUpdate="True"
                                             DisplayMemberPath="ClassificacaoMapa"
                                             HorizontalCellAlignment="Right"/>                                
                            
                        </Controls:SinacorDataGrid.Columns>
                    </Controls:SinacorDataGrid>

                </Grid>
            </Controls:SinacorExpander>
            
            <Controls:SinacorExpander Grid.Row="2"
            	                        HorizontalAlignment="Stretch"
            	                        VerticalAlignment="Stretch"
            	                        Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.Carteiras}"
            	                        IsExpanded="True" 
				                        Margin="0,4,0,0">
                
                <!-- GRID CARTEIRAS -->
                <Grid>
                    <Controls:SinacorDataGrid x:Name="dtgCarteiras"
                                              ItemsSource="{Binding ListaCarteiras}"
            			                      IsSynchronizedWithCurrentItem="True"  
                                              HorizontalAlignment="Stretch"
            			                      Width="Auto" 									
           			                          VerticalAlignment="Stretch" 										
            			                      Margin="0,0,0,0"
                                              EndingInsert="dtgCarteiras_EndingInsert"
                                              EndingUpdate="dtgCarteiras_EndingUpdate"
                                              Deleting="dtgCarteiras_Deleting"
            			                      AllowBeginInsert="True" 
            			                      AllowBeginUpdate="True"
                                              AllowDelete="True"
                                              ApplyingStyle="dtgCarteiras_ApplyingStyle"
						                      TabIndex="6" >
                        
                        <!-- MENU CONTEXTUAL dtgCarteiras -->
                        <Controls:SinacorDataGrid.ContextMenuTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <Controls:SinacorContextMenuItem x:Name="ContextMenu_RelacionarMercadosCarteiras" 
                                                                     Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.RelacionarMercadosCarteiras}"
                                                                     Click="ContextMenu_RelacionarMercadosCarteiras_Click" />
                                    <Controls:SinacorContextMenuItem x:Name="ContextMenu_CancelarRelacionamento" 
                                                                     Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.CancelarRelacionamento}"
                                                                     Click="ContextMenu_CancelarRelacionamento_Click" />
                                    <Controls:SinacorContextMenuItem x:Name="ContextMenu_DefinirCarteiraPrioritaria" 
                                                                     Header="{DynamicResource FaturamentoBovespa.Cadastros.Label.DefinirCarteiraPrioritaria}" 
                                                                     Click="ContextMenu_DefinirCarteiraPrioritaria_Click" />
                                </StackPanel>
                            </DataTemplate>
                        </Controls:SinacorDataGrid.ContextMenuTemplate>
                        
                        <!-- COLUNAS dtgCarteiras -->
                        <Controls:SinacorDataGrid.Columns>
                            <!-- CODIGO -->
                            <Controls:Column Name="Codigo" 
											 Title="FaturamentoBovespa.Cadastros.Label.Codigo" 
                                             AllowInsert="True"
                                             AllowUpdate="False" 
                                             DisplayMemberPath="Codigo"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             HorizontalCellAlignment="Right"                                                                                          
                                             IsRequired="True">

                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorInt16TextBox x:Name="TxtCodigoCarteira" 
                                                                      Value="{Binding Path=Codigo}"
                                                                      IsFormated="False"
                                                                      Integers="3"
                                                                      IsRequired="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>

                            </Controls:Column>
                            <!-- DESCRICAO CARTEIRA -->
                            <Controls:Column Name="DescricaoCarteira" 
            								 Title="FaturamentoBovespa.Cadastros.Label.Descricao" 
                                             AllowInsert="True" 
                                             AllowUpdate="True" 
                                             DisplayMemberPath="Descricao"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             IsRequired="True">
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorTextBox x:Name="TxtDescricaoCarteira" 
                                                                 Text="{Binding Path=Descricao}"                                                                 
                                                                 IsRequired="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>
                            </Controls:Column>

                            <!-- NATUREZA OPERACAO -->
                            <Controls:Column Name="NaturezaOperacao" 
            								 Title="FaturamentoBovespa.Cadastros.Label.NatOper" 
                                             AllowInsert="False" 
                                             AllowUpdate="False" 
                                             DisplayMemberPath="NaturezaOperacao"
                                             HorizontalCellAlignment="Center"/>
                            
                            <!-- CODIGO CUSTODIA -->
                            <Controls:Column Name="CodigoCustodia" 
            								 Title="FaturamentoBovespa.Cadastros.Label.CodCustodia" 
                                             AllowInsert="True"
                                             AllowUpdate="True" 
                                             DisplayMemberPath="CodigoCustodia"                                             
                                             HorizontalCellAlignment="Right"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}"
                                             IsRequired="True">
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorInt32TextBox x:Name="TxtCodigoCustodia" 
                                                                      Value="{Binding Path=CodigoCustodia}"
                                                                      IsFormated="False"
                                                                      Integers="5"
                                                                      IsRequired="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>
                            </Controls:Column>                                
                            
                            <!-- INTEGRA CUSTODIA -->
                            <Controls:Column Name="IntegraCustodia" 
            								 Title="FaturamentoBovespa.Cadastros.Label.IntegraCustodia" 
                                             AllowInsert="True"
                                             AllowUpdate="True" 
                                             DisplayMemberPath="IntegraCustodia"
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}">
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorCheckBox x:Name="ChkIntegraCustodia" 
                                                                  IsChecked="{Binding IntegraCustodia}"
                                                                  IsEnabled="True"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>
                            </Controls:Column>
                            
                            <!-- ACEITA DAYTRADE-->
                            <Controls:Column Name="AceitaDayTrade" 
            								 Title="FaturamentoBovespa.Cadastros.Label.AceitaDayTrade" 
                                             AllowInsert="False"
                                             AllowUpdate="True" 
                                             DisplayMemberPath="AceitaDayTrade"                                             
                                             CellInsertTemplate="{Binding CellUpdateTemplate, RelativeSource={RelativeSource Self}}">
                                
                                <Controls:Column.CellUpdateTemplate>
                                    <DataTemplate>
                                        <Controls:SinacorCheckBox x:Name="ChkAceitaDayTrade" 
                                                                  IsChecked="{Binding AceitaDayTrade}"/>
                                    </DataTemplate>
                                </Controls:Column.CellUpdateTemplate>                                    
                            </Controls:Column>                            
                            
                        </Controls:SinacorDataGrid.Columns>
                    </Controls:SinacorDataGrid>
                </Grid>
            </Controls:SinacorExpander>
            <Grid Margin="0,4,0,0" Grid.Row="3">
                <Controls:SinacorLabel HorizontalAlignment="Left"
                    Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.Legenda}"
                    HorizontalContentAlignment="Left"
                    Width="75"/>
                <Ellipse Fill="{DynamicResource BrushGridRowBusiness01}"
    		        Stroke="{DynamicResource BrushGridRowBusiness10}"
    		        HorizontalAlignment="Left"
    		        Margin="97,0,0,0"
    		        VerticalAlignment="Center"
    		        Width="10"
    		        Height="10"/>
                <Controls:SinacorLabel Foreground="{DynamicResource BrushGridRowBusiness01}"
                    HorizontalAlignment="Left"
                    Width="155"
                    Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.CarteirasRelacionadas}"
                    Margin="110,0,0,0"
                    VerticalAlignment="Top"
                    HorizontalContentAlignment="Left"/>
                <Ellipse Fill="{DynamicResource BrushGridRowBusiness08}"
		            Stroke="{DynamicResource BrushGridRowBusiness10}"
		            HorizontalAlignment="Left"
		            Margin="282,0,0,0"
		            VerticalAlignment="Center"
		            Width="10"
		            Height="10"/>
                <Controls:SinacorLabel Foreground="{DynamicResource BrushGridRowBusiness08}"
            		HorizontalAlignment="Left"
            		Width="180"
            		Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.CarteirasNaoRelacionadas}"
            		Margin="295,0,0,0"
            		VerticalAlignment="Top"
            		HorizontalContentAlignment="Left"/>
                <Ellipse Fill="{DynamicResource BrushGridRowBusiness04}"
            		Stroke="{DynamicResource BrushGridRowBusiness10}"
            		HorizontalAlignment="Left"
            		Margin="505,0,0,0"
            		VerticalAlignment="Center"
            		Width="10"
            		Height="10"/>
                <Controls:SinacorLabel Foreground="{DynamicResource BrushGridRowBusiness04}"
            		HorizontalAlignment="Left"
            		Width="139"
            		Content="{DynamicResource FaturamentoBovespa.Cadastros.Label.CarteirasPrioritarias}"
            		Margin="518,0,0,4"
            		VerticalAlignment="Top"
            		HorizontalContentAlignment="Left"/>
            </Grid>
        </Controls:SinacorExpanderContainer>
    </Grid>
</Controls:SinacorWindow>
